{% extends 'home/register.html' %}

{% block title %}
<title>登录</title>
{% endblock %}

{% block content %}
<div class="banner-box hidden-xs hidden-sm">
			<div class="container">
				<form id="mainForm" class="main-form" method="post">
                    {% csrf_token %}
					<div class="tab-title">
						<a class="linkAGray" id="toAccountLogin" href="javascript:void(0);">账号登录</a>
					</div>
					<div class="tip-box visiblility-hidden">
						<button type="button" class="close" data-dismiss="alert" aria-label="Close">
						  <i class="glyphicon glyphicon-exclamation-sign"></i>
						  <span class="tip-font"></span>
						  <span aria-hidden="true" class="cha">×</span>
						</button>
					</div>


					<div class="normalInput cycode-box fieldInput" id="cycode-box">
						<div class="cycode-selectbox">
							<input class="ipt-account inp-focus" name="username" id="account" maxlength="50" placeholder="用户名" autocomplete="off">
						</div>
					</div>
					<div class="normalInput fieldInput passwd-box">
						<input class="inp-focus" name="password" id="password" maxlength="16" placeholder="密码" autocomplete="off" type="password">
				   </div>
					<div class="normalInput fieldInput passwd-box">
						<input class="inp-focus" name="vcode"  maxlength="16" placeholder="验证码" autocomplete="off" type="text">
						<img src="{% url 'vcode' %}" style="position:absolute;top:10px;right:0px;" onclick="this.src='/admin/vcode?'+Math.random()">
				   </div>

					<button class="button button-3d button-box button-jumbo">登 录</button>
					<div class="transferField">
						<a class="go2forgetpwd linkABlue rememberFieldForA" href="#">忘记密码?</a>
						<a class="go2register linkABlue" href="{% url 'uregister' %}" id="toRegister">注册</a>
					</div>
				</form>
			</div>
		</div>
	<!--提示信息-->
	 <div class="am-form-group tishi1 " style="display:none;position:absolute;left:730px;top:260px;">
		<p style="color:red;">验证码错误,请重新输入</p>
	</div>
	<div class ="tishi3" style="display:none;position:absolute;top:460px;left:990px;"><p style="color:red";>√</p>
	</div>

{% endblock %}

{% block js %}
    <script src="/static/admin/js/jquery-1.8.3.min.js"></script>
<script>

    //判断验证码是否正确:
    // 提示信息定位并且display为隐藏,给input框添加实时监控事件,在里面发送ajax请求,并根据值作出对应的判断
    // 相同:给出√  不同:提示错误  长度不满足:提示信息全部隐藏
    // 用change判断比较好,blur刷新页面就触发ajax
    // ajax 后台接收的函数:def vcodeajax(request): 返回session中保存的验证码

    var d = ''      //验证码值
    var a = ''      //输入的值

    $('input[ name="vcode" ]').bind('input porpertychange',function(){
        $.get('{% url 'vcodeajax' %}',function(data){
            d = data
        },'json');

        // 判断输入的值是否和验证码相等 且长度相等 判断
        var a = $('input[ name="vcode" ]').val();
        if(a != d && a.length == d.length){
            $('.tishi1').css("display","block");
        }
        // 输入长度小于验证码长度,不出现提示
        if (a.length<d.length){
            $('.tishi3').css("display","none");
            $('.tishi1').css("display","none");
        }
        // 输入正确,打勾√
        if (a == d){
            $('.tishi3').css("display","block");
        }
    });

</script>

{% endblock %}